package android.slc.module.user.login

import android.slc.appbase.ui.AppView
import android.slc.box.core.notification.NotificationObserver
import android.slc.module.project.ui.main.MainView
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.fxml.FXML
import javafx.scene.control.Button
import javafx.scene.control.TextField
import javafx.scene.layout.HBox

/**
 * @author slc
 * @date 2022/03/21 下午 3:34
 */
class LoginView : AppView<LoginViewModel>() {

    @FXML
    lateinit var hbPasswordParent: HBox

    @FXML
    lateinit var etAccount: TextField

    @FXML
    lateinit var etPassword: TextField

    @FXML
    lateinit var btnLogin: Button

    override fun onBindView() {
        super.onBindView()
        etAccount.textProperty().bindBidirectional(viewModel.accountSp)
        etPassword.textProperty().bindBidirectional(viewModel.passwordSp)
        btnLogin.onAction = EventHandler { event: ActionEvent? ->
            viewModel.onLogin()
        }
    }

    override fun onRegisterLiveEvent() {
        super.onRegisterLiveEvent()
        this.viewModel.subscribe(LoginViewModel.EVENT_SWITCH_2_MAIN, NotificationObserver { key, payload ->
            this@LoginView.switchView(MainView::class.java)
        })
    }

    override fun onBindViewLater() {
        super.onBindViewLater()
        viewModel.initVm()
    }

}
